package com.wd.live.viewmodel;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.MutableLiveData;

import com.wd.live.base.BaseViewModel;
import com.wd.live.bean.ContellationBeen;
import com.wd.live.bean.FindConstellationBean;
import com.wd.live.bean.FindLeaderBoardBean;
import com.wd.live.bean.LiveTypeListBean;
import com.wd.live.bean.ModifyConstellationBeen;
import com.wd.live.bean.SquareLiveBean;
import com.wd.live.model.HttpUtils;
import com.wd.live.bean.FindLiveListBean;
import com.wd.live.model.SpUtils;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * <p>项目名称:LookFor2.0</p>
 * <p>包名:com.wd.live.viewmodel</p>
 * <p>简述:</p>
 *
 * @author 孟令高
 * @date 2022/11/10
 */
public class MainViewModel extends BaseViewModel {


    public MainViewModel(@NonNull Application application) {
        super(application);
    }
    //修改星座
    MutableLiveData<ModifyConstellationBeen> modifyConData=new MutableLiveData<>();

    public MutableLiveData<ModifyConstellationBeen> getModifyConData(int constellationId) {
        String userId = SpUtils.getString("uid", "");
        Integer integer = Integer.valueOf(userId);
        String sessionId = SpUtils.getString("sid", "");
        HttpUtils.getHttpUtils().getApi().modifyConstellation(integer,sessionId,constellationId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ModifyConstellationBeen>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ModifyConstellationBeen value) {
                     modifyConData.postValue(value);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
        return modifyConData;
    }
    //查询直播类型
    private MediatorLiveData<LiveTypeListBean> livetypeliveData=new MediatorLiveData<>();
    public  MediatorLiveData<LiveTypeListBean> getlivetypelist(){
        HttpUtils.getHttpUtils().getApi()
                .getlivetypelist()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<LiveTypeListBean>() {
                    @Override
                    public void accept(LiveTypeListBean liveTypeListBean) throws Exception {
                        livetypeliveData.postValue(liveTypeListBean);
                    }
                });
        return livetypeliveData;
    }

    //查询星座列表
    MutableLiveData<ContellationBeen> collData=new MutableLiveData<>();

    public MutableLiveData<ContellationBeen> getCollData() {
        HttpUtils.getHttpUtils().getApi()
                .findConstellationList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ContellationBeen>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ContellationBeen value) {
                    collData.postValue(value);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
        return collData;
    }
    private MediatorLiveData<FindLiveListBean> liveData=new MediatorLiveData<>();
    public  MediatorLiveData<FindLiveListBean> getlivelist(int userid,int liveType,int page,int size){
        HttpUtils.getHttpUtils().getApi()
                .getlivelist(userid, liveType, page, size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<FindLiveListBean>() {
                    @Override
                    public void accept(FindLiveListBean findLiveListBean) throws Exception {
                        liveData.postValue(findLiveListBean);
                    }
                });
        return liveData;
    }
    //查询推荐匹配星座列表
    private MediatorLiveData<FindConstellationBean> ConstellationliveData=new MediatorLiveData<>();
    public  MediatorLiveData<FindConstellationBean> getConstellationlist(Map<String,Object> map, int count, int maxFriendId){
        HttpUtils.getHttpUtils().getApi()
                .findConstellation(map, count, maxFriendId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<FindConstellationBean>() {
                    @Override
                    public void accept(FindConstellationBean findRecommendConstellationBean) throws Exception {
                        ConstellationliveData.postValue(findRecommendConstellationBean);
                    }
                });
        return ConstellationliveData;
    }
    //查询排行榜数据
    private MediatorLiveData<FindLeaderBoardBean> findLeaderBoardlivedata=new MediatorLiveData<>();
    public  MediatorLiveData<FindLeaderBoardBean> getfindLeaderBoard(){
        HttpUtils.getHttpUtils().getApi()
                .findLeaderBoard()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<FindLeaderBoardBean>() {
                    @Override
                    public void accept(FindLeaderBoardBean findLeaderBoardBean) throws Exception {
                        findLeaderBoardlivedata.postValue(findLeaderBoardBean);
                    }
                });
        return findLeaderBoardlivedata;
    }
    //查询附近主播
    private MediatorLiveData<SquareLiveBean> findNearbylivedata=new MediatorLiveData<>();
    public  MediatorLiveData<SquareLiveBean> getfindNearbylive(int userid,String longitude, String latitude, int sex, int range){
        HashMap<String, Object> map = new HashMap<>();
        map.put("longitude",longitude);
        map.put("latitude",latitude);
        map.put("sex",sex);
        map.put("range",range);
        HttpUtils.getHttpUtils().getApi()
                .findNearbyLive(userid,map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<SquareLiveBean>() {
                    @Override
                    public void accept(SquareLiveBean squareLiveBean) throws Exception {
                        findNearbylivedata.postValue(squareLiveBean);
                    }
                });

        return findNearbylivedata;
    }
}

